import BaseShape2D from "./BaseShape2D";
import Vector2 from "../maths/Vector2";
import ITransformable from "../interfaces/ITransformable";
import IRenderState from "../interfaces/IRenderState";
import Math2D from "../maths/Math2D";

export default class Circle extends BaseShape2D {
    public radius: number;  //半径

    public get type(): string {
        return "Circle";
    }

    public constructor(radius: number = 1) {
        super();
        this.radius = radius;
    }

    // 调用Math2D类的isPointInCircle静态方法
    public hitTest(localPt: Vector2, transform: ITransformable): boolean {
        return Math2D.isPointInCircle(localPt, Vector2.create(0, 0), this.radius);
    }
    public draw(transformable: ITransformable, state: IRenderState,
        context: CanvasRenderingContext2D): void {
        context.beginPath();
        context.arc(0, 0, this.radius, 0.0, Math.PI * 2.0, true);
        //必须放在最后，调用绘制命令
        super.draw(transformable, state, context);
    }
}